/*
 * @Author: LVGRAPE
 * @Date: 2023-04-13 18:12:33
 * @LastEditTime: 2023-09-08 16:29:31
 * @LastEditors: LVGRAPE
 * @Description:
 * @FilePath: \ZINO_FC_V4\ZINO\dev_info\dev_info.c
 * 可以输入预定的版权声明、个性签名、空行等
 */
#include "dev_info.h"

#define MCU_UNIQUE_96BIT_ID_BASE_ADDR_31_0  ((uint32_t)0x1FFFF7E8)
#define MCU_UNIQUE_96BIT_ID_BASE_ADDR_63_32 ((uint32_t)0x1FFFF7EC)
#define MCU_UNIQUE_96BIT_ID_BASE_ADDR_95_64 ((uint32_t)0x1FFFF7F0)
#define MCU_UNIQUE_ID_0  *(const vu8 *)(MCU_UNIQUE_96BIT_ID_BASE_ADDR_31_0 + 0)
#define MCU_UNIQUE_ID_1  *(const vu8 *)(MCU_UNIQUE_96BIT_ID_BASE_ADDR_31_0 + 1)
#define MCU_UNIQUE_ID_2  *(const vu8 *)(MCU_UNIQUE_96BIT_ID_BASE_ADDR_31_0 + 2)
#define MCU_UNIQUE_ID_3  *(const vu8 *)(MCU_UNIQUE_96BIT_ID_BASE_ADDR_31_0 + 3)
#define MCU_UNIQUE_ID_4  *(const vu8 *)(MCU_UNIQUE_96BIT_ID_BASE_ADDR_31_0 + 4)
#define MCU_UNIQUE_ID_5  *(const vu8 *)(MCU_UNIQUE_96BIT_ID_BASE_ADDR_31_0 + 5)
#define MCU_UNIQUE_ID_6  *(const vu8 *)(MCU_UNIQUE_96BIT_ID_BASE_ADDR_31_0 + 6)
#define MCU_UNIQUE_ID_7  *(const vu8 *)(MCU_UNIQUE_96BIT_ID_BASE_ADDR_31_0 + 7)
#define MCU_UNIQUE_ID_8  *(const vu8 *)(MCU_UNIQUE_96BIT_ID_BASE_ADDR_31_0 + 8)
#define MCU_UNIQUE_ID_9  *(const vu8 *)(MCU_UNIQUE_96BIT_ID_BASE_ADDR_31_0 + 9)
#define MCU_UNIQUE_ID_10 *(const vu8 *)(MCU_UNIQUE_96BIT_ID_BASE_ADDR_31_0 + 10)
#define MCU_UNIQUE_ID_11 *(const vu8 *)(MCU_UNIQUE_96BIT_ID_BASE_ADDR_31_0 + 11)

static const dev_info_t zino_dev_info = {
    .start_key = "__UAVI__",
#if defined (DEV_CORE_ID) && defined (DEV_CORE_NAME)
    .core = {
        .id = DEV_CORE_ID,
        .name = DEV_CORE_NAME,
    },
    #else
    #warning "Devices must have a name - DEV_CORE_NAME"
#endif

#if defined (DEV_NAME) && defined (DEV_ID)
    .device = {
        .id = DEV_ID,
        .name = DEV_NAME,
    },
    #else
    #warning "Devices must have a name - DEV_NAME"
#endif
#ifdef DEV_FEATURE
    .other = {
        .id = 99,
        .name = DEV_FEATURE, // Default name for other device.  Used for device enumeration.  Also used for device name when no name is specified.
    },
#endif // DEBUG
#if defined (DEV_EQP_NAME) && defined (DEV_EQP_ID)
    .equipment = {
        .id = DEV_EQP_ID,
        .name = DEV_EQP_NAME,
    },
    #else
    #warning "Devices must have a name - DEV_EQP_NAME"
#endif
    .build = {
        .id = DEV_BVID,
        .name = __DATE__,
    },
#if defined(DEV_MVID) && defined(DEV_SVID) && defined(DEV_BVID)
    .vid = (((uint32_t)(DEV_MVID)) << 24) | (((uint32_t)(DEV_SVID)) << 16) | (((uint32_t)(DEV_BVID)) << 8),
    #else 
    #warining "Devices must be defined - DEV_MVID, DEV_SVID, and DEV_BVID"
#endif // DEBUG
    .end_key = "__TECH__",
};
uint32_t get_dev_software_version()
{
    return zino_dev_info.vid;
}
uint8_t get_dev_major_verion()
{
    return (zino_dev_info.vid >> 24) & 0x00FF; 	// high byte of the UID is the major version number.  low byte is the revision number.
}
uint8_t get_dev_minor_verion() 	// this is the same as the first byte of the UID.  It is
{
    return (zino_dev_info.vid >> 16) & 0x00FF;
}
uint8_t get_dev_build_number() 	// this is the same as the second byte of the UID.  It is
{
    return (zino_dev_info.vid >> 8) & 0x00FF;
}
const char* get_dev_core_name()
{
    return zino_dev_info.core.name; 	    // Return the name.  It is not a static string.  It is a pointer to a string.
}
const uint16_t get_dev_core_id() 	    // Return the unique ID of the core.  It is not a static number.  It is a 16
{
    return zino_dev_info.core.id; // number.  It is a number.  It is a number.  It is a
}
const char* get_dev_name()
{
    return zino_dev_info.device.name; // Return the name.  It is not a static string.  It is a pointer to a string.
}
const uint16_t get_dev_id() 	    // Return the unique ID of the device.  It is not a static number.  It is a
{
    return zino_dev_info.device.id;
}
const uint16_t get_eqm_id()
{
    return zino_dev_info.equipment.id;
}
const char* get_eqm_name() 	    // Return the name of the device.  It is not a static string.  It is a pointer
{
    return zino_dev_info.equipment.name; // to a string.  It is a pointer to a string.  It is a pointer to a string
}
const uint16_t get_dev_other_id()
{
    return zino_dev_info.other.id; // Return the unique ID of the device.  It is not a static number.  It is a 16 number.  It is a number.  It is a number.  It is a number.  It is a number.  It is a number.  It is a number.  It is a number.  It is a number.  It is a number.  It is a number.  It is a number.  It is a number.  It is a number.  It is a number.  It is a number.  It
}
const char* get_dev_other_name()
{
    return zino_dev_info.other.name; // Return the name of the device.  It is not a static string.  It is a pointer to a
}
int check_dev_info()
{
    rt_kprintf("\n\n* Dev info: %db\n",sizeof(zino_dev_info));
    rt_kprintf("* Core:%d,%s\n", get_dev_core_id(), get_dev_core_name());
    rt_kprintf("* Device:%d,%s\n", get_dev_id(), get_dev_name()); 	    // Print the name.  It is
    rt_kprintf("* Eqm:%d,%s\n", get_eqm_id(), get_eqm_name()); // Print the name.  It is.  It is
    rt_kprintf("* other:%d,%s\n", get_dev_other_id(), get_dev_other_name()); // Print the name.  It is.  It is
    rt_kprintf("* VID: %d.%d.%d\n", get_dev_major_verion(), get_dev_minor_verion(), get_dev_build_number());
    rt_kprintf("* Build date:%s\n\n", __DATE__);
    return 0;
}
ZINO_BOARD_EXPORT(check_dev_info);